/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 
	/// module : levelLogic
	/// </summary>
	public class LevelEntityPOD : IPOD 
    {
        public readonly static Func<LevelEntityPOD> FACTORY = () => new LevelEntityPOD();
		public static Func<LevelEntityPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
		public int id;
		/// <summary>
        /// 
        /// </summary>
		public LevelEntityType type;
		/// <summary>
        /// 
        /// </summary>
		public bool isActive;
		/// <summary>
        /// 
        /// </summary>
		public int x;
		/// <summary>
        /// 
        /// </summary>
		public int y;
		/// <summary>
        /// 
        /// </summary>
		public int z;
		/// <summary>
        /// 每9位一个维度，欧拉角，每9位存储的数值范围为0-359，该字段仅用于初始化朝向
        /// </summary>
		public int dirEuler;
		/// <summary>
        /// 
        /// </summary>
		public bool IsRemoved;
		/// <summary>
        /// 
        /// </summary>
		public LevelNormalEntityPOD normal;
		/// <summary>
        /// 
        /// </summary>
		public LevelHeroEntityPOD hero;
		
		
		
		/*-- constructors --*/
		public LevelEntityPOD() {}
		public LevelEntityPOD(int id, LevelEntityType type, bool isActive, int x, int y, int z, int dirEuler, bool IsRemoved, LevelNormalEntityPOD normal, LevelHeroEntityPOD hero) {
			this.id = id;
			this.type = type;
			this.isActive = isActive;
			this.x = x;
			this.y = y;
			this.z = z;
			this.dirEuler = dirEuler;
			this.IsRemoved = IsRemoved;
			this.normal = normal;
			this.hero = hero;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_int(id);
            _out.Write_byte((sbyte)type);
            _out.Write_boolean(isActive);
            _out.Write_int(x);
            _out.Write_int(y);
            _out.Write_int(z);
            _out.Write_int(dirEuler);
            _out.Write_boolean(IsRemoved);
            _out.Write_pod(normal);
            _out.Write_pod(hero);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            id = _in.Read_int();
            if(!_in.HasRemaining()) return;
            type = (LevelEntityType)_in.Read_byte();
            if(!_in.HasRemaining()) return;
            isActive = _in.Read_boolean();
            if(!_in.HasRemaining()) return;
            x = _in.Read_int();
            if(!_in.HasRemaining()) return;
            y = _in.Read_int();
            if(!_in.HasRemaining()) return;
            z = _in.Read_int();
            if(!_in.HasRemaining()) return;
            dirEuler = _in.Read_int();
            if(!_in.HasRemaining()) return;
            IsRemoved = _in.Read_boolean();
            if(!_in.HasRemaining()) return;
            normal = _in.Read_pod<LevelNormalEntityPOD>(LevelNormalEntityPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            hero = _in.Read_pod<LevelHeroEntityPOD>(LevelHeroEntityPOD.DynamicFactory);
        }
		
		public LevelEntityPOD Clone() {
            LevelEntityPOD o = DynamicFactory();
            o.id = id;
            o.type = type;
            o.isActive = isActive;
            o.x = x;
            o.y = y;
            o.z = z;
            o.dirEuler = dirEuler;
            o.IsRemoved = IsRemoved;
            if (normal != null) {
                o.normal = normal.Clone();
            }
            if (hero != null) {
                o.hero = hero.Clone();
            }
            return o;
        }
        
        public void Clear() {
            id = default;
            type = default;
            isActive = default;
            x = default;
            y = default;
            z = default;
            dirEuler = default;
            IsRemoved = default;
            normal = default;
            hero = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "LevelEntityPOD [";
			str += "id=";
			str += id;
			str += ", type=";
			str += type;
			str += ", isActive=";
			str += isActive;
			str += ", x=";
			str += x;
			str += ", y=";
			str += y;
			str += ", z=";
			str += z;
			str += ", dirEuler=";
			str += dirEuler;
			str += ", IsRemoved=";
			str += IsRemoved;
			str += ", normal=";
			str += normal;
			str += ", hero=";
			str += hero;
			str += "]";
			return str;
		}
		
	}
}